﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.Designer.UI.Editor
{
    /// <summary>
    /// DoubleEditor.xaml 的交互逻辑
    /// </summary>
    public partial class ThinknessEditor : PropertyValueEditor
    {
        public ThinknessEditor()
        {
            InitializeComponent();
            txtLeft.LostFocus += txtValue_LostFocus;
            txtTop.LostFocus += txtValue_LostFocus;
            txtRight.LostFocus += txtValue_LostFocus;
            txtBottom.LostFocus += txtValue_LostFocus;
        }
        void txtValue_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (string.IsNullOrWhiteSpace(tb.Text)) tb.Text = "0";

            Thickness thickness = new Thickness(Convert.ToDouble(txtLeft.Text), Convert.ToDouble(txtTop.Text),
                Convert.ToDouble(txtRight.Text), Convert.ToDouble(txtBottom.Text));

            ChangePropertyValue(thickness);
        }
        protected override void OnPropertyValueChanged(object newValue)
        {
            Thickness thickness = (Thickness)newValue;
            txtLeft.Text = thickness.Left.ToString();
            txtTop.Text = thickness.Top.ToString();
            txtRight.Text = thickness.Right.ToString();
            txtBottom.Text = thickness.Bottom.ToString();
        }
    }
}
